package com.jinchengll.xigua.ui.fragment;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jinchengll.xigua.R;
import com.jinchengll.xigua.constant.ItemType;
import com.jinchengll.xigua.ui.adapter.DiffViewRecyclerViewAdapter;
import com.jinchengll.xigua.ui.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;


public class DiffviewFragment extends BaseFragment {

    private RecyclerView recyclerView;

    public DiffviewFragment() {
    }

    public static DiffviewFragment newInstance() {
        return new DiffviewFragment();
    }

    @Override
    protected void initData() {
        List<ItemType> itemTypes = new ArrayList<>();
        ItemType[] arr = {ItemType.Image, ItemType.Text};
        for (int i = 0; i < 10; i++) {
            // 增加一个横向滑动item
            if (i == 5) itemTypes.add(ItemType.RecyclerView);
            itemTypes.add(arr[i & 1]);
        }
        DiffViewRecyclerViewAdapter adapter = new DiffViewRecyclerViewAdapter(itemTypes, getContext());
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initView(View view) {
        recyclerView = view.findViewById(R.id.diffviewRecyclerView);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_diffview;
    }
}